﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HNQXYJ.BLL;
using HNQXYJ.Model;

namespace HNQXYJ.HN_AreaGroup
{
    public partial class AreaGroupAdd : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        //添加新的分组
        protected void add_Click(object sender, ImageClickEventArgs e)
        {
            string ranklevel = Session["ranklevel"].ToString();
            AreaGroupBLL agb = new AreaGroupBLL();
            AreaGroup ag = new AreaGroup();
            ag.Name = this.txtGroupName.Text.Trim();
            ag.RankLevel = ranklevel;
            ag.DateAdd = DateTime.Now;
            ag.Notes = this.txtNotes.Text.Trim();
            int max = agb.GetAreaCodeMax(ranklevel+"%");
            if (max == -1)
            {
                //如果max为-1说明该权限下还没有一个分组
                ag.AreaCode = ranklevel + "000";              
              
            }
            else {
                //该权限下已经存在分组，新的分组要在原有分组的基础上编码
                int maxCount = Convert.ToInt32(max);
                ag.AreaCode = (maxCount + 1).ToString();
            }

            int res = agb.AddNewGroup(ag);
            if (res > 0)
            {
                this.Label1.Text = "添加成功";
                Response.Redirect("AreaGroupMgr.aspx");
            }
            else
            {
                this.Label1.Text = "失败";
            }


        }

        protected void reset_Click(object sender, ImageClickEventArgs e)
        {
            Response.Redirect("AreaGroupMgr.aspx");
        }
    }
}